package com.zaoqi.provider.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/provider")
public class FeignController {

    private Map<Integer, String> data = new HashMap<>();
    @Value("8003")
    private String port;

    @PostMapping
    public String postData(@RequestParam Integer id, @RequestParam String value) {
        data.put(id, value);
        System.out.println("【Provider】收到 POST 添加数据：id=" + id + ", value=" + value);
        return "POST: 数据添加成功";
    }

    @GetMapping("/{id}")
    public String getData(@PathVariable Integer id) {
        return "【Provider@" + port + "】处理了 ID = " + id;
    }

    @PutMapping
    public String putData(@RequestParam Integer id, @RequestParam String value) {
        data.put(id, value);
        return "PUT: 数据更新成功";
    }

    @DeleteMapping("/{id}")
    public String deleteData(@PathVariable Integer id) {
        data.remove(id);
        return "DELETE: 数据删除成功";
    }
}



